import { Options, Vue } from 'vue-class-component'
import navigator from '@/components/common/navigator.vue'
import store from '@/store'
import { ElMessage } from 'element-plus'
import router from '@/router'

interface iAuditSuccessInfo {
  conditionSheetId: string
  commodityName: string
  commodityDescription: string
  commodityPrice: number
}

@Options({
  components: {
    navigator
  }
})

export default class shoppingMall extends Vue {
  conditionSheetsArray: any[] = []
  auditSuccessInfoParams: iAuditSuccessInfo = {
    conditionSheetId: '',
    commodityName: '',
    commodityDescription: '',
    commodityPrice: 0
  }
  mounted () {
    store.dispatch('getConditionSheetsWhereOnStateIsOne').then(response => {
      this.conditionSheetsArray = response.data.data
      console.log(this.conditionSheetsArray)
    })
  }

  auditSuccess(index, rows){
    this.auditSuccessInfoParams.conditionSheetId = rows[index].conditionSheetId
    this.auditSuccessInfoParams.commodityName = rows[index].commodityName
    this.auditSuccessInfoParams.commodityDescription = rows[index].commodityDescription
    this.auditSuccessInfoParams.commodityPrice = rows[index].commodityPrice
    store.dispatch('auditSuccess', this.auditSuccessInfoParams).then(response => {
      if (response.data.code === 200){
        console.log('success')
        location.reload()
      }
    })
  }

  auditFail(index, rows){
    this.auditSuccessInfoParams.conditionSheetId = rows[index].conditionSheetId
    this.auditSuccessInfoParams.commodityName = rows[index].commodityName
    this.auditSuccessInfoParams.commodityDescription = rows[index].commodityDescription
    this.auditSuccessInfoParams.commodityPrice = rows[index].commodityPrice
    store.dispatch('auditFail', this.auditSuccessInfoParams).then(response => {
      if (response.data.code === 200){
        console.log('success')
        location.reload()
      }
    })
  }
}
